package dch.db;

import java.sql.Connection;
import java.sql.SQLException;

import javax.naming.Context;
import javax.naming.InitialContext;
import javax.sql.DataSource;

public class DataBasePool {

	private static DataSource pool;
	static{
		Context env=null;
		try{
			env=(Context)new InitialContext().lookup("java:comp/env");
			pool=(DataSource)env.lookup("jdbc/dbpool");
			if(null==pool){
				System.err.print("DBPool is an unknown DataSource");
			}
		}catch(Exception e){
			e.printStackTrace();
		}
	}
	
	public static Connection getConnection(){
		Connection conn=null;
		try {
			conn=pool.getConnection();
		} catch (SQLException e) {
			e.printStackTrace();
		}
		return conn;
	}
}
